package com.example.demo.mapper;

import com.example.demo.model.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Select("SELECT * FROM `order` WHERE order_id = #{id}")
    Order findById(String id);

    @Select("SELECT * FROM `order` WHERE user_id = #{userId} ORDER BY created_at DESC")
    List<Order> findByUserId(String userId);

    @Select("SELECT * FROM `order` WHERE status = #{status}")
    List<Order> findByStatus(String status);

    @Insert("INSERT INTO `order`(order_id, user_id, table_no, status, total_amount) " +
            "VALUES(#{orderId}, #{userId}, #{tableNo}, #{status}, #{totalAmount})")
    int insert(Order order);

    @Update("UPDATE `order` SET " +
            "status=#{status} " +
            "WHERE order_id=#{orderId}")
    int updateStatus(Order order);

    @Delete("DELETE FROM `order` WHERE order_id=#{id}")
    int delete(String id);
}